package logic

import (
	"context"
	"wxapi/internal/services"

	"wxapi/internal/svc"
	"wxapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSkillsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetSkillsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSkillsListLogic {
	return &GetSkillsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetSkillsListLogic) GetSkillsList() (resp *types.GetSkillListResp, err error) {
	list, err := services.GetSkillList(l.ctx, l.svcCtx)
	if err != nil {
		return nil, err
	}

	resp = &types.GetSkillListResp{
		Skills: make([]types.Skill, 0, len(list)),
	}
	for _, skill := range list {
		resp.Skills = append(resp.Skills, types.Skill{
			ID:     skill.ID,
			Name:   skill.SkillName,
			Avatar: skill.SkillAvatar,
			Desc:   skill.SkillDesc,
		})
	}

	return
}
